﻿using System;
using System.Collections.Generic;
using System.Web;
using Spring.Data.NHibernate;
using AppToolKit.Core.Context.Spring;
using System.Diagnostics;
using System.Data;
using AppToolKit.Model;
using Model;


namespace BLL
{
    [AutoWiring]
    public class ConvertService 
    {
        [AutoWiring]
        public HibernateConvert ConvertHolder
        {
            get;
            set;
        }

        /// <summary>
        /// 数据列转成VO
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dataTable"></param>
        /// <param name="row"></param>
        /// <param name="instance"></param>
        public void DataRowToVO<T>(DataTable dataTable, int row, ref T instance) where T : IEntity
        {
            Debug.Assert(dataTable.Rows.Count > row);
            ConvertHolder.CopyFrom(typeof(T), instance, dataTable.Rows[row]);
        }
        public void DataRowToVO(DataRow row, DataTrans data)
        {
            int Col_Length = data.Entity.Cols.Count;
            for (int i = 0; i < Col_Length; i++)
            {
                data.Entity.Cols[i].Value = row[data.Entity.Cols[i].Column];
            }
            int Key_Length = data.Entity.PrimaryKey.Keys.Count;

            for (int j = 0; j < Key_Length; j++)
            {
                data.Entity.PrimaryKey.Keys[j].Value = row[data.Entity.PrimaryKey.Keys[j].Column];
            }
        }
    }
}
